
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
import  com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
import  com.wechat.pay.java.service.payments.jsapi.model.PrepayResponse;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import com.wechat.pay.java.service.payments.jsapi.model.Amount;

/** Native 支付下单为例 */
public class QuickStart {

    /** 商户号 */
    public static String merchantId = "1641994941";
    /** 商户API私钥路径 */
    public static String privateKeyPath = "C:\\Users\\Administrator\\IdeaProjects\\smile_ai\\smile_client_server\\src\\main\\resources\\apiclient_key.pem";
    /** 商户证书序列号 */
    public static String merchantSerialNumber = "72216618A7EF7B51E25B36E072CF893669B7FBFD";
    /** 商户APIV3密钥 */
    public static String apiV3Key = "9385jsfjsdodif9sdugesojgegweksdl";

    public static void main(String[] args) {
        // 使用自动更新平台证书的RSA配置
        // 一个商户号只能初始化一个配置，否则会因为重复的下载任务报错
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(merchantId)
                        .privateKeyFromPath(privateKeyPath)
                        .merchantSerialNumber(merchantSerialNumber)
                        .apiV3Key(apiV3Key)
                        .build();
        // 构建service
        JsapiService service = new JsapiService.Builder().config(config).build();
        // request.setXxx(val)设置所需参数，具体参数可见Request定义
        PrepayRequest request = new PrepayRequest();
        Amount amount = new Amount();
        amount.setTotal(100);
        request.setAmount(amount);
        request.setAppid("wx5fe7aa6f5124747f");
        request.setMchid(merchantId);
        request.setDescription("测试商品标题");
        request.setNotifyUrl("https://secondpretty.com:9090/client/pay/notify");
        request.setOutTradeNo("1700770208775098369");
        Payer payer = new Payer();
        payer.setOpenid("oK6g85Rzhnc2PJaq1Hf6hQAOvjpY");
        request.setPayer(payer);
        // 调用下单方法，得到应答
        PrepayResponse response = service.prepay(request);
        // 使用微信扫描 code_url 对应的二维码，即可体验Native支付
        System.out.println(response.getPrepayId());
    }
}
